package com.situ.mall.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.situ.mall.admin.pojo.query.RoleQuery;
import com.situ.mall.admin.service.IRoleService;
import com.situ.mall.common.util.Result;
import com.situ.mall.pojo.entity.admin.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Gao
 * @since 2024-11-29
 */
@RestController
@RequestMapping("/admin/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @GetMapping("/list")
    public Result<IPage<Role>> list(RoleQuery roleQuery) {
        IPage<Role> page = roleService.list(roleQuery);
        return Result.ok(page);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Role role) {
        roleService.save(role);
        return Result.ok("添加成功");
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Long id) {
        Role role = roleService.getById(id);
        return Result.ok(role);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Role role) {
        roleService.updateById(role);
        return Result.ok("更新成功");
    }
    
}

